cd  "/Users/tobiasbohmelt/Google Drive/IO_UNPI/II Graphs/"

* First Graph *

use worlddata.dta
spmap PKO using worldcoor.dta if admin!="Antarctica", id(id) clmethod(unique) name(graph1, replace)
spmap mission_new using worldcoor.dta if admin!="Antarctica", id(id) clmethod(unique) name(graph2, replace)
graph combine graph1 graph2

use "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/PPKO_MissionYear_data_Primary.dta", clear
keep mission_id political_mission cow_code year thematiccluster
drop if cow_code==-9999
drop if cow_code==.
kountry cow_code,from(cown) to(cowc)
drop if thematiccluster==.
gen number=1 if cow_code>400 & cow_code<600
label define thematic 1 Dipl. 2 Techn. 3 Devel. 4 PKO
label values thematiccluster thematic
twoway (scatter thematiccluster year if number==1, sort), by(_COWC_) scheme(plotplain)

* Second Graph *

use "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/PPKO_MissionYear_data_Country.dta", clear
keep mission_id political_mission year
egen min=min(year), by(mission_id)
egen max=max(year), by(mission_id)
rename min start_year
rename max end_year
export excel using "Missions.xls"

* Third Graph *

use "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/PPKO_MissionYear_data_Primary.dta", clear
keep mission_id political_mission cow_code year thematiccluster
drop if cow_code==-9999
drop if cow_code==.
drop if thematiccluster==.
tab thematiccluster, gen(dummy)
egen sum1=total(dummy1), by(year)
egen sum2=total(dummy2), by(year)
egen sum3=total(dummy3), by(year)
egen sum4=total(dummy4), by(year)
collapse sum1 sum2 sum3 sum4, by(year)
keep if year<2016
twoway (line sum1 year), scheme(plotplain) name(graph1, replace) aspectratio(1)
twoway (line sum2 year), scheme(plotplain) name(graph2, replace) aspectratio(1)
twoway (line sum3 year), scheme(plotplain) name(graph3, replace) aspectratio(1)
twoway (line sum4 year), scheme(plotplain) name(graph4, replace) aspectratio(1)
graph combine graph1 graph2 graph3 graph4, ycommon

* Fourth Graph *

use "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/PPKO_MissionYear_data_Primary.dta", clear
keep ucdpid_primary_type_1 ucdpid_primary_type_2 ucdpid_primary_type_3 mission_id thematiccluster
rename ucdpid_primary_type_1 before
rename ucdpid_primary_type_2 during
rename ucdpid_primary_type_3 after
replace before=0 if before==1 & after==1
drop if before==.
drop if during==.
drop if after==.
drop if thematiccluster==.
tab thematiccluster, gen(dummy)
egen sum1=total(dummy1) if before==1
egen sum2=total(dummy1) if during==1
egen sum3=total(dummy1) if after==1
egen bar1=max(sum1) if dummy1==1
egen bar2=max(sum2) if dummy1==1
egen bar3=max(sum3) if dummy1==1
drop sum*
egen sum1=total(dummy2) if before==1
egen sum2=total(dummy2) if during==1
egen sum3=total(dummy2) if after==1
egen bar11=max(sum1) if dummy2==1
egen bar22=max(sum2) if dummy2==1
egen bar33=max(sum3) if dummy2==1
replace bar1=bar11 if bar1==.
replace bar2=bar22 if bar2==.
replace bar3=bar33 if bar3==.
drop sum1-bar33
egen sum1=total(dummy3) if before==1
egen sum2=total(dummy3) if during==1
egen sum3=total(dummy3) if after==1
egen bar11=max(sum1) if dummy3==1
egen bar22=max(sum2) if dummy3==1
egen bar33=max(sum3) if dummy3==1
replace bar1=bar11 if bar1==.
replace bar2=bar22 if bar2==.
replace bar3=bar33 if bar3==.
drop sum1-bar33
egen sum1=total(dummy4) if before==1
egen sum2=total(dummy4) if during==1
egen sum3=total(dummy4) if after==1
egen bar11=max(sum1) if dummy4==1
egen bar22=max(sum2) if dummy4==1
egen bar33=max(sum3) if dummy4==1
replace bar1=bar11 if bar1==.
replace bar2=bar22 if bar2==.
replace bar3=bar33 if bar3==.
drop sum1-bar33
collapse bar1 bar2 bar3, by(thematiccluster)
label variable bar1 "Before conflict"
label variable bar2 "During conflict"
label variable bar3 "After conflict"
graph bar bar1 bar2 bar3, over(thematiccluster) stack scheme(plotplain) horizontal legend(label(1 "Before Conflict") label(2 "During Conflict") label(3 "After Conflict"))

* Fifth Graph *

use "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/PPKO_MissionYear_data_Primary.dta", clear
keep rep_class
drop if rep_class==""
export excel using "rep_class.xls"
import excel "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/rep_class.xls", sheet("Sheet1") clear
stack A B C D E , into(y)
drop if y==.
histogram y, scheme(plotplain) xlabel(1(1)29) discrete frequency

use "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/PPKO_MissionYear_data_Primary.dta", clear
keep ga_class
drop if ga_class==""
export excel using "ga_class.xls"
import excel "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/ga_class.xls", sheet("Sheet1") clear
stack A B C D , into(y)
drop if y==.
histogram y, scheme(plotplain) xlabel(1(1)16) discrete frequency

* Sixth Graph *

use "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/PPKO_MissionYear_data_Primary.dta", clear
sum estab_instit auth_instit
drop if estab_instit==-99
egen max1=max(estab_instit), by(mission_id)
egen max2=max(auth_instit), by(mission_id)
replace estab_instit=max1
replace auth_instit=max2
collapse estab_instit auth_instit, by(mission_id)
graph pie, over(estab_instit) scheme(plotplain)
graph pie, over(auth_instit) scheme(plotplain)

* Seventh Graph *

use "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/PPKO_MissionYear_data_Primary.dta", clear
keep function
drop if function=="-99"
drop if function=="-9999"
export excel using "function.xls"
import excel "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/function.xls", sheet("Sheet1") clear
stack A-U , into(y)
drop if y==.
drop if y>40
histogram y, scheme(plotplain) xlabel(1(1)40) discrete frequency

* Eighth Graph *

use "/Users/tobiasbohmelt/Google Drive/IO_UNPI/Data/Complete Datasets/PPKO_CivilConflictYear.dta", clear
keep tc1_d tc2_d tc3_d tc4_d bdbest_ucdp duration
gen thematic=.
replace thematic=1 if tc1_d==1
replace thematic=2 if tc2_d==1
replace thematic=3 if tc3_d==1
replace thematic=4 if tc4_d==1
replace duration=ln(1+duration)
replace bdbest_ucdp=ln(bdbest_ucdp)
twoway (scatter duration bdbest_ucdp if thematic==1) (scatter duration bdbest_ucdp if thematic==2) (scatter duration bdbest_ucdp if thematic==3) (scatter duration bdbest_ucdp if thematic==4), legend(on) scheme(plotplain)  aspectratio(1)





